package com.ww.disruptor.producer;

import com.lmax.disruptor.RingBuffer;
import com.ww.disruptor.event.Order;

/**
 * TODO
 *
 * @author wanggw
 * @date 2024-09-15 13:37:39
 */
public class Producer {

    private RingBuffer<Order> ringBuffer;

    public Producer(RingBuffer<Order> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void sendData(String uuid) {
        final long sequence = ringBuffer.next();

        try {
            final Order order = ringBuffer.get(sequence);
            order.setId(uuid);
        } finally {
            ringBuffer.publish(sequence);
        }
    }
}
